home *** CD-ROM | disk | FTP | other *** search
- #ifdef lint
- static char *SCCSid = "%W% (NCSA) %G%";
- #endif
-
- /*
-
- rgmac.c by Gaige B. Paulsen
- spawned from rgp.c by Aaron Contorer for NCSA
- Copyright 1987, board of trustees, University of Illinois
-
- Routines for Macintosh Window output.
-
- */
-
-
- /*
- * Include files
- */
-
- #include <stdio.h>
- #include <String.h>
-
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <OSutils.h>
- #include <Packages.h>
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <Memory.h>
-
- #ifdef MPW
- #include "mpw.h"
- #endif MPW
- #include "configrec.h"
- #include "maclook.h"
- #include "whatami.h"
- #include "vgtek.h"
- #include "tools.h"
- #include "util.h"
- #include "rsmac.h"
-
- #define TRUE 1
- #define FALSE 0
-
- #define SPLASH_SQUARED 4
-
- /*
- * display structure....
- */
-
- struct RGMwindows {
- GrafPtr
- wind;
- int
- xorigin,
- yorigin,
- xscale,
- yscale,
- vg,
- vs,
- inuse,
- ingin;
- unsigned char
- *name;
- int
- width,
- height;
- ControlHandle
- zoom,
- vert,
- horiz;
- } *RGMwind[ MAXWIND ]; /* BYU - changed from an array of structure to an array of pointers */
-
- long RGMlastclick;
-
- int RGMcolor[]=
- { 30, /* black */
- 33, /* white */
- 205, /* red */
- 341, /* green */
- 409, /* blue */
- 273, /* cyan */
- 137, /* magenta */
- 69 /* yellow */
- };
-
-
- char *macname = "Macintosh Windows";
-
- int RGsetwind
- (
- int dnum
- )
- {
-
- if (dnum<0 || dnum>=MAXWIND) return(-1);
-
- if (!RGMwind[dnum]->inuse) return(-1);
-
- SetPort( RGMwind[dnum]->wind);
- return(0);
- }
-
- RGMgin(w)
- {
- if (RGsetwind(w)) return(-1);
-
- setgraphcurs();
- RGMwind[w]->ingin=1;
- }
-
- RGMoutfunc(f)
- int (*f)();
- {
- #pragma unused(f)
- }
-
-
- RGMpencolor(w, color)
- {
- if (RGsetwind(w) ) return(-1);
-
- ForeColor((long) RGMcolor[color] );
- }
-
- RGMclrscr(w)
- {
- if (RGsetwind(w) ) return(-1);
-
- PaintRect(&RGMwind[w]->wind->portRect);
- }
-
- RGMclose(w)
- {
- if (RGsetwind(w) ) return(-1);
-
- DisposeWindow(RGMwind[w]->wind);
- RGMwind[w]->inuse = FALSE;
-
- }
-
- RGMpoint(w,x,y)
- {
- if (RGsetwind(w) ) return(-1);
-
- MoveTo(x,y);
- LineTo(x,y);
- }
-
- RGMdrawline(w,x0,y0,x1,y1)
- int w,x0,y0,x1,y1;
- {
- if (RGsetwind(w) ) return(-1);
-
- x0 = (int) ((long) x0 * RGMwind[w]->width / INXMAX);
- y0 = RGMwind[w]->height - (int) ((long) y0 * RGMwind[w]->height / INYMAX);
- x1 = (int) ((long) x1 * RGMwind[w]->width/INXMAX);
- y1 = RGMwind[w]->height - (int) ((long) y1 * RGMwind[w]->height / INYMAX);
-
- MoveTo(x0,y0);
- LineTo(x1,y1);
- }
-
- RGMpagedone(w)
- {
- #pragma unused(w)
- }
-
- RGMdataline(w,data,count)
- {
- #pragma unused(w, data, count)
- }
-
-
- RGMcharmode(w,rotation,size)
- {
- #pragma unused(w, rotation, size)
- }
-
- RGMshowcur()
- {
- }
-
- RGMlockcur()
- {
- }
-
- RGMhidecur()
- {
- }
-
- RGMbell(w)
- {
- #pragma unused(w)
- }
-
- RGMuncover(w)
- {
- #pragma unused(w)
- }
-
- char *RGMdevname() {
- return(macname);
- }
-
- int RGMalloc() /* BYU - allocate this structure to save global space */
- { /* BYU */
- int i; /* BYU */
- for(i=0; i<MAXWIND; i++) { /* BYU */
- RGMwind[i] = (struct RGMwindows *) NewPtr((long) sizeof(struct RGMwindows)); /* BYU */
- if (RGMwind[i]) { /* BYU */
- RGMwind[i]->wind = (GrafPtr) 0; /* BYU */
- RGMwind[i]->vg = -1; /* BYU - necessary */
- RGMwind[i]->vs = -1; /* BYU */
- RGMwind[i]->inuse = 0; /* BYU - necessary */
- } else /* BYU */
- return -1; /* BYU - insufficient memory */
- } /* BYU */
- return(0); /* BYU */
- } /* BYU */
-
- RGMinit()
- {
- int i;
- for (i = 0; i < MAXWIND; i++)
- RGMwind[i]->inuse = 0;
- }
-
- RGMinfo(w,v,a,b,c,d)
- int w,a,b,c,d,v;
- {
- #pragma unused(a, b, c, d)
- RGMwind[w]->vg=v;
- }
-
- RGMgmode()
- {}
-
- RGMtmode()
- {}
-
- RGMnewwin()
- {
- int i = 0;
- int maxdim =0;
-
- while ((i < MAXWIND) && (RGMwind[i]->inuse)) i++;
-
- if (i >= MAXWIND) return(-1);
-
- RGMwind[i]->wind = GetNewWindow(256, (Ptr) 0L, (WindowPtr) -1L);
-
- if (RGMwind[i]->wind == 0L) return(-1);
- if (qd.screenBits.bounds.bottom > 400)
- {
- SizeWindow(RGMwind[i]->wind, 400, 300, FALSE);
- maxdim = 400;
- }
- else
- maxdim = 342;
-
- RGMwind[i]->vg = -1; /* BYU */
- RGMwind[i]->vs = -1; /* BYU */
- RGMwind[i]->xorigin = 0;
- RGMwind[i]->yorigin = 0;
- RGMwind[i]->xscale = WINXMAX; /* BYU 2.4.7 - added the "W" */
- RGMwind[i]->yscale = WINYMAX; /* BYU 2.4.7 - added the "W" */
- RGMwind[i]->width = maxdim; /* BYU 2.4.7 - was 256 */
- RGMwind[i]->height = (maxdim*3)/4; /* BYU 2.4.7 - was 342 */
- RGMwind[i]->inuse = TRUE;
- RGMwind[i]->ingin = 0;
-
- ValidRect(&RGMwind[i]->wind->portRect);
-
- return(i);
- }
-
- int RGfindbyVG
- (
- int vg
- )
- {
- int i = 0;
-
- while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->vg != vg)))
- i++;
- if (i >= MAXWIND) return(-1);
- return(i);
- }
-
- int RGattach
- (
- int vg,
- int virt,
- char *name
- )
- {
- int dnum;
- long time;
- char myname[256],ts[256];
-
- if ((dnum = RGfindbyVG(vg)) < 0) return(-1);
-
- sprintf(ts,"RGattach: vg = %d, vs = %d, \042%s\042); dnum = %d", /* BYU */
- vg,virt,name,dnum); /* BYU */
- putln(ts);
-
- RGMwind[dnum]->vs = virt;
- RGMwind[dnum]->name = (char *) NewPtr((long) 256); /* BYU */
-
- if (RGMwind[dnum]->name == 0L) return(-2);
-
- #if 1 /* BYU */
- myname[0] = 165; /* BYU - the "dot" */
- strncpy(&myname[1],name,254); /* BYU - don't copy too much */
- #else /* BYU */
- RGMwind[dnum]->name[0] = 165;
- strncpy(&RGMwind[dnum]->name[1],name,255);
- #endif /* BYU */
-
- GetDateTime((unsigned long *) &time);
- iutimestring(time,FALSE,ts); /* Put time in the temp string */
-
- #if 1 /* BYU */
- strncat(myname," ",4); /* BYU - Space, please */
- strncat(myname,ts,64); /* BYU - Place the time string at the end */
- strcpy(RGMwind[dnum]->name,myname); /* BYU */
- #else /* BYU */
- strncat(RGMwind[dnum]->name," ",255); /* Space, please */
- strncat(RGMwind[dnum]->name,ts,255); /* Place the time string at the end */
- #endif
-
- #if 1 /* BYU */
- if (RGMwind[dnum]->wind != (GrafPtr) 0) /* BYU */
- setwtitle(RGMwind[dnum]->wind,myname); /* BYU */
- #else /* BYU */
- setwtitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);
- #endif /* BYU */
- return(0);
- }
-
-
- int RGdetach /* BYU */
- (
- int vg /* BYU */
- )
- {
- int dnum; /* BYU */
- char temp[64];
-
- if ((dnum = RGfindbyVG(vg)) < 0) return(-1); /* BYU */
- if (dnum >= MAXWIND) return(-1); /* BYU */
-
- sprintf(temp,"RGdetach: dnum = %d, vg = %d, vs = %d, Wind = %lx", /* BYU */
- dnum,RGMwind[dnum]->vg,RGMwind[dnum]->vs,RGMwind[dnum]->wind); /* BYU */
- putln(temp);
- if (RGMwind[dnum]->vs != -1) { /* BYU */
- if (RGMwind[dnum]->wind != (GrafPtr) 0) { /* BYU */
- strncpy(RGMwind[dnum]->name,&RGMwind[dnum]->name[1],255); /* BYU */
- setwtitle(RGMwind[dnum]->wind,RGMwind[dnum]->name); /* BYU */
- } /* BYU */
- } /* BYU */
- return(0); /* BYU */
- }
-
- int RGfindbywind
- (
- GrafPtr wind
- )
- {
- int i = 0;
-
- while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->wind != wind)))
- i++;
- if (i >= MAXWIND) return(-1);
- return(i);
- }
-
- int RGupdate
- (
- GrafPtr wind
- )
- {
- int i = 0,done;
-
- if ((i = RGfindbywind(wind)) < 0)
- return(-1);
-
- SetPort(wind);
- BeginUpdate(wind);
-
- VGstopred(RGMwind[i]->vg);
- VGpage(RGMwind[i]->vg);
- done = VGpred(RGMwind[i]->vg,RGMwind[i]->vg);
- EndUpdate(wind);
- if (!done)
- netputevent(1,128,RGMwind[i]->vg);
- return(done);
- }
-
- int RGsupdate
- (
- int i
- )
- {
- int rg;
-
- rg = RGfindbyVG(i);
-
- if (rg < 0) return(0);
- SetPort(RGMwind[rg]->wind);
- if (!VGpred(RGMwind[rg]->vg,RGMwind[rg]->vg))
- {
- netputevent(1,128,i);
- }
- else
- return(1);
- return(0);
- }
-
- int RGgetVG
- (
- GrafPtr wind
- )
- {
- int i;
-
- i = RGfindbywind(wind);
-
- return(RGMwind[i]->vg);
- }
-
- int RGgetdnum
- (
- GrafPtr wind
- )
- {
- return(RGfindbywind(wind));
- }
-
- int RGgetVS
- (
- int dnum
- )
- {
- return(RGMwind[dnum]->vs);
- }
-
- inSplash(p1, p2)
- Point *p1,*p2;
- {
- if ((p1->h - p2->h > 3) || (p2->h - p1->h > 3))
- return(0);
- if ((p1->v - p2->v > 3) || (p2->v - p1->v > 3))
- return(0);
-
- return(1);
- }
-
- long *Ticks = (long *) 0x16a;
-
- void VidSync
- (
- void
- )
- {
- long a;
-
- a = *Ticks;
- while (a == *Ticks);
- }
-
- /*
- Resize the tek window. It will always be sqare.
- */
-
- void RGsize (GrafPtr wind, Point * where)
- {
- union {
- Point pt;
- long lg;
- } size;
- Rect SizRect;
- int i;
-
- if ((i = RGfindbywind(wind)) < 0)
- return;
-
- SetRect(&SizRect, 48, 48, 2000,2000);
-
- if (where)
- { /* grow icon actions */
- size.lg = growwindow(wind, (Point *) where, &SizRect);
- if ((long) size.lg != 0L)
- {
- if (size.pt.h > size.pt.v)
- size.pt.h = size.pt.v;
- else
- size.pt.v = size.pt.h;
-
- if ((long) size.lg)
- {
- SizeWindow(wind, size.pt.h, size.pt.v, FALSE);
- RGMwind[i]->width = size.pt.h;
- RGMwind[i]->height = size.pt.h;
- SetPort (wind);
- InvalRect(&wind->portRect); /* Don't forget to redraw */
- }
- }
- else
- return; /* user skipped growing */
- }
-
- }
-
- void RGmousedown
- (
- GrafPtr wind,
- Point *wherein
- )
- {
- long lx,ly;
- char thispaceforent[6];
- int i;
- Point where;
- char dum[32];
-
- where = *wherein;
- if ((i = RGfindbywind(wind)) < 0)
- return;
-
- if (!RGMwind[i]->ingin)
- {
- Point anchor,current,last;
- #ifndef MPW
- long TickCount();
- #endif MPW
- long tc;
- int x0,y0,x1,y1;
- Rect rect;
-
- SetPort(wind);
-
- last = where;
- current = where;
- anchor = where;
-
- PenPat((ConstPatternParam)qd.gray);
- PenMode(patXor);
-
- SetRect(&rect,0,0,0,0);
-
- while (StillDown())
- {
- GetMouse(¤t);
- if (inSplash(¤t,&anchor)) continue;
-
- if ((current.h - anchor.h)*4 < 3*(current.v - anchor.v)) /* tlr */
- current.h = (anchor.h + (current.v - anchor.v))*4/3;
- else
- current.v = (anchor.v + (current.h - anchor.h))*3/4;
-
- tc = TickCount();
- while(TickCount() == tc);
- VidSync();
- FrameRect(&rect);
-
- if (anchor.v < current.v)
- {
- rect.top = anchor.v;
- rect.bottom = current.v;
- }
- else
- {
- rect.top = current.v;
- rect.bottom = anchor.v;
- }
-
- if (anchor.h < current.h)
- {
- rect.left = anchor.h;
- rect.right = current.h;
- }
- else
- {
- rect.right = anchor.h;
- rect.left = current.h;
- }
-
- FrameRect(&rect);
- last = current;
- }
-
- FrameRect(&rect);
-
- PenPat(qd.black);
- PenMode(patCopy);
-
- if (!inSplash(&anchor,¤t))
- {
- x0 = (int) ((long) rect.left * RGMwind[i]->xscale / RGMwind[i]->width );
- y0 = (int) (RGMwind[i]->yscale -
- (long) rect.top * RGMwind[i]->yscale / RGMwind[i]->height);
- x1 = (int) ((long) rect.right * RGMwind[i]->xscale / RGMwind[i]->width);
- y1 = (int) (RGMwind[i]->yscale -
- (long) rect.bottom * RGMwind[i]->yscale / RGMwind[i]->height);
- x1 = (x1 < x0+2) ? x0 + 4 : x1;
- y0 = (y0 < y1+2) ? y1 + 4 : y0;
-
- VGzoom( i,
- x0 + RGMwind[i]->xorigin,
- y1 + RGMwind[i]->yorigin,
- x1 + RGMwind[i]->xorigin,
- y0 + RGMwind[i]->yorigin);
-
- VGpage(RGMwind[i]->vg);
-
- RGMwind[i]->xscale = x1 - x0;
- RGMwind[i]->yscale = y0 - y1;
- RGMwind[i]->xorigin = x0 + RGMwind[i]->xorigin;
- RGMwind[i]->yorigin = y1 + RGMwind[i]->yorigin;
-
- while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
- Stask();
- RGMlastclick = 0L;
- }
- else
- {
- if (RGMlastclick && ((RGMlastclick + GetDblTime()) > TickCount()))
- {
- RGMwind[i]->xscale = WINXMAX; /* BYU 2.4.7 - added the "W" */
- RGMwind[i]->yscale = WINYMAX; /* BYU 2.4.7 - added the "W" */
- RGMwind[i]->xorigin = 0;
- RGMwind[i]->yorigin = 0;
-
- VGzoom(i,0,0,WINXMAX-1,WINYMAX-1); /* BYU 2.4.7 - added the "W" */
- VGpage( RGMwind[i]->vg);
- while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
- Stask();
- RGMlastclick = 0L;
- }
- else RGMlastclick = TickCount();
- }
- return;
-
- }
-
- lx = (RGMwind[i]->xscale * where.h) / ((long) RGMwind[i]->width);
- ly = RGMwind[i]->yscale -
- ((RGMwind[i]->yscale * where.v) / ((long) RGMwind[i]->height));
-
- VGgindata(RGMwind[i]->vg,(int) lx,(int) ly,' ',thispaceforent);
-
- sprintf(dum,"GIN i: %d, vs: %d\n",i,RGMwind[i]->vs);
- putln(dum);
-
- RSsendstring(RGMwind[i]->vs,thispaceforent,5);
- sprintf(dum," \r\n");
- RSsendstring(RGMwind[i]->vs,dum,3);
-
-
- /* RGMwind[i]->ingin = 0; */
- unsetgraphcurs();
- RGMlastclick = TickCount();
- }
-
- void RGMgetrect
- (
- int src,
- Rect * inRect
- )
- {
- inRect->top = 0;
- inRect->left = 0;
- inRect->bottom = RGMwind[src]->height;
- inRect->right = RGMwind[src]->width;
- return;
- }
-